import * as globalTypes from '../../../mutation-types'
// import * as types from './mutation-types'
import questionnaireConfig from '../../../api/config/questionnaire-config'

/**
 * 查询问卷模板详情
 * @param data
 * @returns {*}
 */
export const queryAccountQuestionnaireTemp = ({commit, state, rootState, dispatch}, data) => {
  return questionnaireConfig.queryAccountQuestionnaireTemp(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 获取模板的信息配置
 * @param data
 * @returns {*}
 */
export const getQuestionnaireTempById = ({commit, state, rootState, dispatch}, data) => {
  return questionnaireConfig.getQuestionnaireTempById(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 查询问卷模板字段
 * @param data
 * @returns {*}
 */
export const queryQuestionnaireFields = ({commit, state, rootState, dispatch}, data) => {
  return questionnaireConfig.queryQuestionnaireFields(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 添加问卷模板
 * @param data
 * @returns {*}
 */
export const addQuestionnaireTemp = ({commit, state, rootState, dispatch}, data) => {
  return questionnaireConfig.addQuestionnaireTemp(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 问卷模板状态配置
 * @param data
 * @returns {*}
 */
export const getQuestionnaireTempStatusById = ({commit, state, rootState, dispatch}, data) => {
  return questionnaireConfig.getQuestionnaireTempStatusById(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 保存问卷模板的问卷状态
 * @param data
 * @returns {*}
 */
export const updateQuestionnaireTempStatusById = ({commit, state, rootState, dispatch}, data) => {
  return questionnaireConfig.updateQuestionnaireTempStatusById(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 根据id获取字段信息
 * @param data
 * @returns {*}
 */
export const getQuestionnaireFieldById = ({commit, state, rootState, dispatch}, data) => {
  return questionnaireConfig.getQuestionnaireFieldById(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 更新模板在字段
 * @param data
 * @returns {*}
 */
export const updateQuestionnaireFields = ({commit, state, rootState, dispatch}, data) => {
  return questionnaireConfig.updateQuestionnaireFields(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 增加问卷模板字段
 * @param data
 * @returns {*}
 */
export const addQuestionnaireFields = ({commit, state, rootState, dispatch}, data) => {
  return questionnaireConfig.addQuestionnaireFields(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 更新模板的信息配置
 * @param data
 * @returns {*}
 */
export const updateQuestionnaireTemp = ({commit, state, rootState, dispatch}, data) => {
  return questionnaireConfig.updateQuestionnaireTemp(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 停用模板
 * @param data
 * @returns {*}
 */
export const changeStatusQuestionnaireTemp = ({commit, state, rootState, dispatch}, data) => {
  return questionnaireConfig.updateQuestionnaireTemp(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 获取问卷问题列表
 * @param data
 * @returns {*}
 */
export const queryQuestionnaireQues = ({commit, state, rootState, dispatch}, data) => {
  return questionnaireConfig.queryQuestionnaireQues(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 根据问题id获取详细信息
 * @param data
 * @returns {*}
 */
export const getQuesById = ({commit, state, rootState, dispatch}, data) => {
  return questionnaireConfig.getQuesById(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 检查问卷模板是否已经被用
 * @param data
 * @returns {*}
 */
export const checkTempIsUsed = ({commit, state, rootState, dispatch}, data) => {
  return questionnaireConfig.checkTempIsUsed(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 添加问题
 * @param data
 * @returns {*}
 */
export const addQuestionnaireQues = ({commit, state, rootState, dispatch}, data) => {
  return questionnaireConfig.addQuestionnaireQues(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 删除问题
 * @param data
 * @returns {*}
 */
export const delTempQues = ({commit, state, rootState, dispatch}, data) => {
  return questionnaireConfig.delTempQues(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 问卷导入任务列表
 * @param data
 * @returns {*}
 */
export const queryQuestionTask = ({commit, state, rootState, dispatch}, data) => {
  return questionnaireConfig.queryQuestionTask(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 问卷导入任务详情
 * @param data
 * @returns {*}
 */
export const queryQuestionTaskImport = ({commit, state, rootState, dispatch}, data) => {
  return questionnaireConfig.queryQuestionTaskImport(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 问卷导入，获取excel文件的头信息
 * @param data
 * @returns {*}
 */
export const getQuesXlsHeads = ({commit, state, rootState, dispatch}, data) => {
  return questionnaireConfig.getXlsHeads(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 问卷导入
 * @param data
 * @returns {*}
 */
export const quesConfigImport = ({commit, state, rootState, dispatch}, data) => {
  return questionnaireConfig.quesImport(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 问卷删除
 * @param data
 * @returns {*}
 */
export const removeQuesTask = ({commit, state, rootState, dispatch}, data) => {
  return questionnaireConfig.removeQuesTask(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 动静结合模板   问题位置 调整
 * @param data
 * @returns {*}
 */
export const changeQuesOrder = ({commit, state, rootState, dispatch}, data) => {
  return questionnaireConfig.changeQuesOrder(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
